﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_UPDMS_ETC_LEGO_MGT_Get_Search_Count')
	BEGIN
		DROP Procedure usp_UPDMS_ETC_LEGO_MGT_Get_Search_Count
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : usp_UPDMS_ETC_LEGO_MGT_Get_Search_Count
**	Desc : 레고관리의 검색결과수를 카운트한다.
**	Test Exec Query : Exec usp_UPDMS_ETC_LEGO_MGT_Get_Search_Count
**	Called by : Etc_Dac_UPDMS_ETC_LEGO_MGT.cs
**	Program ID : Etc1014m
**	Auth : 송시명
**	Date : 2014-09-11
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**			
*******************************************************************************/
CREATE PROC [dbo].[usp_UPDMS_ETC_LEGO_MGT_Get_Search_Count]
@ls_buy_dt_from nvarchar(10),
@ls_buy_dt_to nvarchar(10),
@ls_series nvarchar(max),
@ls_prod_no varchar(10),
@ls_prod_nm nvarchar(200),
@ls_contents nvarchar(max),
@ls_order_by nvarchar(5),
@ls_asc_desc nvarchar(5)
AS
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT ON

DECLARE @series nvarchar(max)
IF @ls_series = ''
BEGIN
    SET @series = '%'
END
ELSE
BEGIN
    SET @series = @ls_series
END

SELECT COUNT(Seq) AS Search_Count
  FROM UPDMS_ETC_LEGO_MGT WITH(NOLOCK)
 WHERE Buy_Dt >= @ls_buy_dt_from
   AND Buy_Dt <= @ls_buy_dt_to
   AND (Series IN (SELECT Rslt FROM dbo.ufn_UPDMS_Get_Rslt_At_Comma(@series))
       OR Series LIKE @series
       )
   AND Prod_No LIKE '%' + @ls_prod_no + '%'
   AND Prod_Nm LIKE '%' + @ls_prod_nm + '%'
   AND Contents LIKE '%' + @ls_contents + '%'

GO